package com.atguigu.gmallre.mock.log;



import com.atguigu.gmallre.mock.bean.UserInfo;
import com.atguigu.gmallre.mock.config.AppConfig;
import com.atguigu.gmallre.mock.factory.UserSession;
import com.atguigu.mock.util.RandomNum;
import com.atguigu.gmallre.mock.log.enums.ItemType;
import com.atguigu.mock.util.RandomNumBuilder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static com.atguigu.gmallre.mock.config.AppConfig.*;


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AppDisplay {

    ItemType item_type;

    String item;


    Integer pos_seq;

    Integer pos_id;

    Collection<Long> activityIds;

    Integer max_size =null;




    public static class AppDisplayBuilder {

        public   List<AppDisplay> buildList() {
            List<AppDisplay> displayList = new ArrayList();


            if(activityIds!=null&&activityIds.size()>0){
                //banner增加活动页
                for (Long activityId : this.activityIds) {
                    AppDisplay appDisplay = new AppDisplay();
                    appDisplay.setPos_id(1);
                    appDisplay.setPos_seq(1); ;
                    appDisplay.setItem_type(ItemType.activity_id);
                    appDisplay.setItem(activityId+"");
                    displayList.add(appDisplay);
                }

            }
            int curSize = displayList.size();
            Integer displaySize=RandomNum.getRandInt(1,max_size);

            UserInfo userInfo = UserSession.getUserInfo();

            for (int i = curSize; i <= displaySize; i++) {
                Long skuId =getSkuIdByUser(  userInfo);




                AppDisplay appDisplay = new AppDisplay();
                appDisplay.setPos_id(this.pos_id);
                appDisplay.setPos_seq(i); ;
                appDisplay.setItem_type(ItemType.sku_id);
                appDisplay.setItem(skuId+"");
                displayList.add(appDisplay);
            }


            return displayList;
        }

        public Long getSkuIdByUser(UserInfo userInfo){
            String gender=null;
            if(userInfo!=null){
                gender= userInfo.getGender();
            }

            Long skuId=0L;
            if("M".equals(gender)){
                skuId= skuRandomBuilderM.getNum()+0L ;
            }else if("F".equals(gender)){
                skuId= skuRandomBuilderF.getNum()+0L ;
            }else{
                if(userInfo==null){
                    skuId= new RandomNum().getRandLong(1,35);
                }
                else if( userInfo.getId()%2 == 0 ){
                    skuId=skuRandomBuilderF.getNum()+0L ;
                }else{
                    skuId=skuRandomBuilderM.getNum()+0L ;
                }

            }
            return  skuId;

        }

    }




    public static void main(String[] args) {

    }
}

